package com.durian.affairs.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.durian.affairs.api.vo.CwDealPerDaySum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.durian.common.log.annotation.Log;
import com.durian.common.log.enums.BusinessType;
import com.durian.common.security.annotation.RequiresPermissions;
import com.durian.affairs.api.domain.CwDealPerDay;
import com.durian.affairs.service.ICwDealPerDayService;
import com.durian.common.core.web.controller.BaseController;
import com.durian.common.core.web.domain.AjaxResult;
import com.durian.common.core.utils.poi.ExcelUtil;
import com.durian.common.core.web.page.TableDataInfo;

/**
 * 营业报表Controller
 * 
 * @author durian
 * @date 2022-06-22
 */
@RestController
@RequestMapping("/cwDealPerDay")
public class CwDealPerDayController extends BaseController
{
    @Autowired
    private ICwDealPerDayService cwDealPerDayService;

    /**
     * 查询营业报表列表
     */
    @RequiresPermissions("affairs:cwDealPerDay:list")
    @GetMapping("/list")
    public AjaxResult list(CwDealPerDay cwDealPerDay)
    {
        startPage();
        //查询营业报表列表列表
        List<CwDealPerDay> list = cwDealPerDayService.selectCwDealPerDayList(cwDealPerDay);
        TableDataInfo dataTable = getDataTable(list);
        //统计所有的总和
        CwDealPerDaySum summation = cwDealPerDayService.getSummation(cwDealPerDay);
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.put("list",dataTable);
        ajaxResult.put("summation",summation);
        return ajaxResult;
    }

    /**
     * 导出营业报表列表
     */
    @RequiresPermissions("affairs:cwDealPerDay:export")
    @Log(title = "营业报表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CwDealPerDay cwDealPerDay)
    {
        List<CwDealPerDay> list = cwDealPerDayService.selectCwDealPerDayList(cwDealPerDay);
        ExcelUtil<CwDealPerDay> util = new ExcelUtil<CwDealPerDay>(CwDealPerDay.class);
        util.exportExcel(response, list, "营业报表数据");
    }

    /**
     * 获取营业报表详细信息
     */
    @RequiresPermissions("affairs:cwDealPerDay:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cwDealPerDayService.selectCwDealPerDayById(id));
    }

    /**
     * 新增营业报表
     */
    @RequiresPermissions("affairs:cwDealPerDay:add")
    @Log(title = "营业报表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CwDealPerDay cwDealPerDay)
    {
        return toAjax(cwDealPerDayService.insertCwDealPerDay(cwDealPerDay));
    }

    /**
     * 修改营业报表
     */
    @RequiresPermissions("affairs:cwDealPerDay:edit")
    @Log(title = "营业报表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CwDealPerDay cwDealPerDay)
    {
        return toAjax(cwDealPerDayService.updateCwDealPerDay(cwDealPerDay));
    }

    /**
     * 删除营业报表
     */
    @RequiresPermissions("affairs:cwDealPerDay:remove")
    @Log(title = "营业报表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cwDealPerDayService.deleteCwDealPerDayByIds(ids));
    }
}
